home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 007 / jovept2.arc / TERM.C < prev    next >
Text File  |  1985-05-30  |  4KB  |  211 lines

  1. /* term.c */
  2.  
  3. /* JOVE/MSDOS. K. Mitchum 1/85 */
  4. /* Modifications for personal use only. */
  5. /* original code J. Payne LSRHS 5/83 */
  6. /* Ken Mitchum */
  7. /* University of Pittsburgh */
  8. /* Decision Systems Laboratory */
  9. /*
  10.    Jonathan Payne at Lincoln-Sudbury Regional High School 5-25-83
  11.  
  12.    jove_term.c
  13.  
  14.    Gets the termcap information and complains if there are not enough
  15.    of the basic features on the particular terminal. */
  16.  
  17. #define JOVETERM
  18. #include "term.h"
  19. #include "tune.h"
  20. #ifdef UNIX
  21. #include <sgtty.h>
  22. #endif
  23.  
  24. extern int CanScroll;
  25.  
  26. /* Termcap definitions */
  27.  
  28. char    *UP,    /* Scroll reverse, or up */
  29.     *VT,    /* If on vt100 */
  30.     *SO,    /* Start standout */
  31.     *SE,    /* End standout */
  32.     *CM,    /* The cursor motion string */
  33.     *CL,    /* Clear screen */
  34.     *CE,    /* Clear to end of line */
  35.     *HO,    /* Home cursor */
  36.     *AL,    /* Addline (insert line) */
  37.     *DL,    /* Delete line */
  38.     *IS,    /* Initial start */
  39.     *VS,    /* Visual start */
  40.     *VE,    /* Visual end */
  41.     *IC,    /* Insert char    */
  42.     *DC,    /* Delete char    */
  43.     *IM,    /* Insert mode */
  44.     *EI,    /* End insert mode */
  45.     *LL,    /* Move to last line, first column of screen */
  46.     *BC,    /* Back space */
  47.     *SR,
  48.     *VB;
  49.  
  50. int    LI,        /* Number of lines */
  51.     CO,        /* Number of columns */
  52.     TABS,        /* Whether we are in tabs mode */
  53.     UpLen,        /* Length of the UP string */
  54.     HomeLen,    /* Length of Home string */
  55.     LowerLen;    /* Length of lower string */
  56.  
  57. int    BG;        /* Are we on a bitgraph? */
  58.  
  59. int ospeed;
  60. int hasIC;
  61. int hasIM;
  62. char    tspace[128];
  63.  
  64. char **meas[] = {
  65.     &VS, &VE, &IS, &AL, &DL, &VT, &SO, &SE,
  66.     &CM, &CL, &CE, &HO, &UP, &BC, &IC, &IM,
  67.     &DC, &EI, &LL, &SR, &VB, 0
  68. };
  69.  
  70. /*----------------------------o.s. dependent-------------------------*/
  71. #ifdef UNIX
  72.  
  73.  
  74. gets(buf)
  75. char    *buf;
  76. {
  77.     buf[read(0, buf, 12) - 1] = 0;
  78. }    
  79.  
  80. char    *sprint();
  81.  
  82. TermError(str)
  83. char    *str;
  84. {
  85.     char    *cp;
  86.  
  87.     cp = sprint("Termcap error: %s\n", str);
  88.     if (write(1, cp, strlen(cp)));
  89.     exit(1);
  90. }
  91.  
  92.  
  93. #ifdef TERMCAP
  94. getTERM()
  95. {
  96.     char    *getenv();
  97.     struct sgttyb tty;
  98.     char    *ts="vsveisaldlvtsosecmclcehoupbcicimdceillsrvb";
  99.     char    termbuf[13],
  100.         *termname = 0,
  101.         *termp = tspace,
  102.         tbuff[1024];
  103.     int    i;
  104.  
  105.     if (gtty(0, &tty))
  106.         TermError("ioctl fails");
  107.     TABS = !(tty.sg_flags & XTABS);
  108.     ospeed = tty.sg_ospeed;
  109.  
  110.     termname = getenv("TERM");
  111.     if (termname == 0) {
  112.         putstr("Enter terminal name: ");
  113.         gets(termbuf);
  114.         if (termbuf[0] == 0)
  115.             TermError("");
  116.  
  117.         termname = termbuf;
  118.     }
  119.  
  120.     BG = strcmp(termname, "bg") == 0;    /* Kludge to help out bg scroll */
  121.  
  122.     if (tgetent(tbuff, termname) < 1)
  123.         TermError("terminal type?");
  124.  
  125.     if ((CO = tgetnum("co")) == -1)
  126.         TermError("columns?");
  127.  
  128.     if ((LI = tgetnum("li")) == -1)
  129.         TermError("lines?");
  130.  
  131.     for (i = 0; meas[i]; i++) {
  132.         *(meas[i]) = (char *)tgetstr(ts,&termp);
  133.         ts += 2;
  134.     }
  135. /* You can decide whether you want this ... */
  136.     if (!CE || !UP)
  137.         TermError("Your terminal sucks!");
  138. }
  139.  
  140. weight(n)
  141. int n;
  142. {
  143.     switch (n) {
  144.        case (DELETE) : return strlen(DC);
  145.        case (CLREOL) : return strlen(CE);
  146.        case (INSERTCH) : return strlen(IC);
  147.        case (INSERT) : return strlen(IM);       
  148.        default: return;
  149.     }
  150. }
  151.  
  152. #else
  153. getTERM(type)
  154. int type;
  155. {
  156.     struct sgttyb tty;
  157.  
  158.     char    termbuf[13],
  159.         *termname = 0,
  160.         *termp = tspace,
  161.         tbuff[1024];
  162.  
  163.  
  164.  
  165.     if (gtty(0, &tty))
  166.         TermError("ioctl fails");
  167.     TABS = !(tty.sg_flags & XTABS);
  168.     ospeed = tty.sg_ospeed;
  169.     BG = 0;
  170.     LI =Trm();
  171.     hasIM = 1;
  172.     hasIC = 1;
  173.     CO = 80;
  174.     CanScroll = 1;
  175.  
  176. }
  177.  
  178. weight(n)
  179. int n;
  180. {
  181.     return(2);
  182. }
  183. #endif
  184.  
  185.     
  186. #else
  187.  
  188. /* clone */
  189.  
  190. getTERM()
  191. {
  192.     TABS = 0;
  193.     ospeed = 0;
  194.     BG = 0;
  195.     LI = Trm();
  196.     hasIM = 1;
  197.     hasIC = 1;
  198.     CO = 80;
  199.     CanScroll = 1;
  200. }
  201.  
  202. weight(n)
  203. int n;
  204. {
  205.     return(2);
  206. }
  207.  
  208. #endif
  209.  
  210. /* end */
  211.